
#
# @lc app=leetcode.cn id=141 lang=python3
#
# [141] 环形链表
#
from typing import Optional

from sqlalchemy import true

class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
# @lc code=start
# Definition for singly-linked list.


class Solution:
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        s = set()
        while head is not None:
            if head in s:
                return True
            s.add(head)
            head = head.next
           
        return False
        
# @lc code=end

s = Solution()
head = ListNode(1)
head.next = ListNode(2)
print(s.hasCycle(head))
